// import store from '/store/index.js'; //vuex  
// 判断是否在开发环境
// const server_url = process.env.NODE_ENV === 'development' ? '/api' : 'api';
// http://192.168.1.26:8080
// let server_url = 'http://192.168.1.74:7614/public'; //请求地址
let server_url = 'http://192.168.31.196:8888'; //请求地址

//凭证
let token = '';
function service(options = {}) {
	token = uni.getStorageSync('token') || '' //从缓存中获取登录凭证
	// store.state.token && (token = store.state.token); //从vuex中获取登录凭证
	options.url = `${server_url}${options.url}`;
	//配置请求头
	options.header = {
		'content-type': 'application/json',
		// 'Authorization': `${token}` //Bearer 	
		'Authorization': 'Bearer ' + token,
	};

	return new Promise((resolved, rejected) => {
		//成功
		options.success = (res) => {

			// if (Number(res.data.code) == 0) { //请求成功
			// 	resolved(res.data);
			// }
			// else if (Number(res.data.code) == 401) {
			// 	uni.showToast({
			// 		icon: 'none',
			// 		duration: 3000,
			// 		title: `${res.data.msg}`
			// 	});
			// 	uni.navigateTo({
			// 		url: '/pages/index/index'
			// 	})
			// }
			// else {
			// 	uni.showToast({
			// 		icon: 'none',
			// 		duration: 3000,
			// 		title: `${res.data.msg}`
			// 	});
			// 	rejected(res.data); //错误
			// }

		}
		//错误
		options.fail = (err) => {
			rejected(err); //错误
		}
		uni.request(options);

	});
}
export default service;
